package k2_oop.p7_javaLang.demo01;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GetNewsTitle {
    public static void main(String[] args) {
        //复制网页中的部分html代码，模拟爬虫爬取下来的完整页面
        String page = "<div class=\"qqhome-content-row qqhome-content-gap\">\n" +
                "        <div class=\"qqhome-col-2\">\n" +
                "          <!-- 指令区 -->\n" +
                "          <div id=\"qqhome-command-area\"><div class=\"command-area-wrap\" data-reactroot=\"\"><div class=\"command-area\"><div class=\"top-article\"><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/20250325A07X6R00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A07X6R00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A07X6R00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">擦亮新时代党的建设“金色名片”</a></div><div class=\"command-item\"><a href=\"https://news.qq.com/rain/a/20250324A0465N00\" target=\"_blank\" rel=\"noopener\" class=\"link-item\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250324A0465N00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250324A0465N00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">总书记为何强调实施十年的制度还是要坚持</a><span class=\"split-line\">|</span><a href=\"https://news.qq.com/rain/a/20250324A03R8U00\" target=\"_blank\" rel=\"noopener\" class=\"link-item\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250324A03R8U00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250324A03R8U00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">总书记说这个群体很不容易</a></div></div><div class=\"qqhome-content-row\" dt-imp-once=\"true\" dt-eid=\"em_content_card\" dt-clck-ignore=\"true\" dt-params=\"card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;dt_element_path=[&#x27;em_content_card&#x27;]\"><div class=\"qqhome-col-1\"><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/20250325A02JDQ00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A02JDQ00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A02JDQ00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">“吃住行游”一站式康养 银发族爱上“候鸟式”旅居</a><a href=\"https://news.qq.com/rain/a/20250325A01AYV00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A01AYV00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A01AYV00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">擦亮作风建设这张“金色名片”（思想纵横）</a><a href=\"https://news.qq.com/rain/a/20250324A066B700\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250324A066B700&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250324A066B700&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">最高可贷5000万元！金融助企稳岗扩岗力度加大</a></div><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/20250324A09QRH00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250324A09QRH00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250324A09QRH00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">广西三江侗乡：一片绿叶托起富民“金饭碗”</a><a href=\"https://news.qq.com/rain/a/20250325A01XKL00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A01XKL00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A01XKL00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">凡人微光｜AI有温度</a><a href=\"https://news.qq.com/rain/a/LNK2025032500930300\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=LNK2025032500930300&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/LNK2025032500930300&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">美国企业家：美国不是民主国家 国会议员代表金钱而非人民</a><a href=\"https://news.qq.com/rain/a/20250323A060NC00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250323A060NC00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250323A060NC00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">管好你的体重，是个人的事也是国家的事</a></div><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/20250325A02ONB00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A02ONB00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A02ONB00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">中国经济新脉动：大力发展县域经济，释放什么信号？</a><a href=\"https://news.qq.com/rain/a/20250325A03Y3L00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A03Y3L00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A03Y3L00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">以新质生产力推动传统产业转型升级</a><a href=\"https://news.qq.com/rain/a/20250325A01GDS00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A01GDS00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A01GDS00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">协调秩序与温度  优化消费环境需“软硬”兼施</a></div><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/20250325A06U9T00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A06U9T00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A06U9T00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">全球瞭望｜英媒：关税政策等打击“美国例外论”</a><a href=\"https://news.qq.com/rain/a/20250325A038RU00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A038RU00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A038RU00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">德意志银行调查：美国陷入经济衰退的可能性接近50%</a></div></div><div class=\"qqhome-col-1\"><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/20250325A06CEL00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A06CEL00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A06CEL00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">统筹发展和安全 民企更好“走出去”</a><a href=\"https://news.qq.com/rain/a/LNK2025032500594200\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=LNK2025032500594200&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/LNK2025032500594200&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">一南一北两座古城，今天如何保持“顶流”？</a><a href=\"https://news.qq.com/rain/a/20250324A09K0Q00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250324A09K0Q00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250324A09K0Q00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">春日游玩好去处！这些运河值得你来一场Citywalk</a></div><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/LNK2025032500532200\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=LNK2025032500532200&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/LNK2025032500532200&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">晶采观察丨“最炫民族风”探索文旅融合新动能</a><a href=\"https://news.qq.com/rain/a/20250325A026VY00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A026VY00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A026VY00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">第二批城市更新典型案例发布</a><a href=\"https://news.qq.com/rain/a/20250325A0A6IT00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A0A6IT00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A0A6IT00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">以钉钉子精神推进作风建设</a></div><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/20250325A07NEU00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A07NEU00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A07NEU00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">海南博鳌：为全球“零碳标准”提供“中国答案”</a><a href=\"https://news.qq.com/rain/a/20250325A04PUR00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A04PUR00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A04PUR00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">在博鳌感受开放的中国</a><a href=\"https://news.qq.com/rain/a/20250325A05WB500\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A05WB500&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A05WB500&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">欧美企业高管齐聚北京，用实际行动反驳“脱钩论”</a></div><div class=\"command-item command-item-lunbo\"><a href=\"https://news.qq.com/rain/a/LNK2025032500926000\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=LNK2025032500926000&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/LNK2025032500926000&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">阿根廷前国防官员： 共建“一带一路”为拉美带来新机遇</a><a href=\"https://news.qq.com/rain/a/20250325A06DNN00\" target=\"_blank\" rel=\"noopener\" class=\"link-item lunbo-link\" dt-imp-once=\"true\" dt-eid=\"em_item_article\" dt-params=\"article_id=20250325A06DNN00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A06DNN00&amp;dt_element_path=[&#x27;em_item_article&#x27;,&#x27;em_content_card&#x27;]\">期待希中两国继续合作共赢——访希腊驻华大使卡尔佩里斯</a></div></div></div></div></div></div>\n" +
                "        </div>" +
                "      </div>";

        /**
         * <div class="command-item command-item-lunbo">
         *     <a href="https://news.qq.com/rain/a/20250325A06CEL00" target="_blank" rel="noopener" class="link-item lunbo-link lunbo-link-show" dt-imp-once="true" dt-eid="em_item_article" dt-params="article_id=20250325A06CEL00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250325A06CEL00&amp;dt_element_path=['em_item_article','em_content_card']">统筹发展和安全 民企更好“走出去”</a>
         *     <a href="https://news.qq.com/rain/a/LNK2025032500594200" target="_blank" rel="noopener" class="link-item lunbo-link" dt-imp-once="true" dt-eid="em_item_article" dt-params="article_id=LNK2025032500594200&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/LNK2025032500594200&amp;dt_element_path=['em_item_article','em_content_card']">一南一北两座古城，今天如何保持“顶流”？</a>
         *     <a href="https://news.qq.com/rain/a/20250324A09K0Q00" target="_blank" rel="noopener" class="link-item lunbo-link" dt-imp-once="true" dt-eid="em_item_article" dt-params="article_id=20250324A09K0Q00&amp;card_name=%E6%8C%87%E4%BB%A4%E5%8C%BA&amp;url=https://new.qq.com/rain/a/20250324A09K0Q00&amp;dt_element_path=['em_item_article','em_content_card']">春日游玩好去处！这些运河值得你来一场Citywalk</a>
         * </div>
         */
        String regex =
//                "<div class=\"command-item command-item-lunbo\">" +
                "<a\\s+href=\".*?\"\\s+target=\"_blank\"\\s+rel=\"noopener\"\\s+" +
                "class=\"link-item\\s+lunbo-link\"\\s+" +
                "dt-imp-once=\"true\"\\s+dt-eid=\"em_item_article\"\\s+" +
                "dt-params=\".*?\">(.*?)</a>";
//                "</div>";

        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(page);

        while(matcher.find()){
            System.out.println(matcher.group(1));
        }

    }
}
